package com.controller;

import com.dto.AddGroupInfoDTO;
import com.entity.GroupInfo;
import com.service.GroupInfoService;
import com.vo.ResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 群信息控制器
 *
 * @author lbb
 * @version 1.0
 * @date 2020.3.20
 */
@RestController
@RequestMapping("/api")
public class GroupInfoController {
	
	@Autowired
	private GroupInfoService groupInfoService;
	
	/**
	 * 对群信息进行修改
	 * 可修改的内容为：群昵称、群头像、群描述
	 * 根据群ID或是群号进行修改
	 *
	 * @param groupInfo 群修改信息
	 * @return
	 */
	@PostMapping("/groupInfo/edit")
	public ResponseVO editGroupInfo(@RequestBody GroupInfo groupInfo) {
		return new ResponseVO("200",null,groupInfoService.editGroupInfo(groupInfo));
	}
	
	/**
	 * 根据群号查找群
	 * @param groupNum 群号
	 * @return
	 */
	@GetMapping("/groupInfo/getByNum")
	public ResponseVO getByNumGroupInfo(String groupNum) {
		return new ResponseVO("200",null,groupInfoService.getByNumGroupInfo(groupNum));
	}
	
	/**
	 * 创建群
	 * @param addGroupInfoDTO
	 * @return
	 */
	@PostMapping("/groupInfo/add")
	public ResponseVO addGroupInfo(@RequestBody AddGroupInfoDTO addGroupInfoDTO) {
		ResponseVO vo = new ResponseVO();
		Boolean bool = groupInfoService.addGroupInfo(addGroupInfoDTO.getGroupInfo(),addGroupInfoDTO.getUserId());
		if (bool) {
			vo.setCode("200");
			vo.setMsg("创建成功！");
		} else {
			vo.setCode("500");
			vo.setMsg("创建失败！");
		}
		return vo;
	}

	/**
	 * 解散群
	 * @param groupId
	 * @return
	 */
	@PostMapping("/groupInfo/del")
	public ResponseVO delGroupInfo(Integer groupId){
		return new ResponseVO("200",null,groupInfoService.delGroupInfo(groupId));
	}
}
